<template>
    <div id="app">
        <keep-alive>
            <router-view v-if="$route.meta.keepAlive" />
        </keep-alive>
        <router-view v-if="!$route.meta.keepAlive" />
    </div>
</template>

<script>
    window.smFinish = '80F5EA938E0C5F877DF07C';
    import Setting from './setting';
    import { accountLoginOut, keepsSessionHeart } from "@/api/isc.js";
    import network from "@/assets/js/network.js";
    export default {
        data () {
            return {
                timer: null
            }
        },
        created () {
            if (sessionStorage.getItem('userInfo')) {
                this.$store.commit('setUserInfo', JSON.parse(sessionStorage.getItem('userInfo')));
            }
        },
        mounted () {
            // 心跳（5s）
            // keepsSessionHeart();
            // this.timer = setInterval(() => {
            //     keepsSessionHeart();
            // }, 5000)
        },
        beforeDestroy () {
            if (this.timer) {
                clearInterval(this.timer);
                this.timer = null;
            }
        }
    }
    {
        ("use strict");
        wx.ready(function () {
            console.log(wx)
            wx.hideAllNonBaseMenuItem();
            wx.onHistoryBack(function () {
                if (confirm("是否确定退出该应用？")) {
                    accountLoginOut();
                    return true;
                } else {
                    return false;
                }
            });
            network();
            wx.invoke("ext_DeviceInfo_GetInfo", { data: {} }, function (res) {
                if (false && res.deviceType.indexOf('iPhone') !== -1) {
                    let deviceType = res.deviceType.replace(/ /g, '');
                    // let arr = [480, 568, 667, 736, 812, 896, 812, 844, 852, 926, 932]
                    if (["iPhone6Plus", "iPhone6SPlus", "iPhone7Plus", "iPhone8Plus"].indexOf(deviceType) !== -1 || window.innerHeight < 800) { // 20px
                        document.querySelector("html").classList.add('pageDown');
                        sessionStorage.setItem('htmlClass', 'pageDown');
                    } else if (["iPhoneXSMax", "iPhone11ProMax"].indexOf(deviceType) !== -1) { // 42px
                        document.querySelector("html").classList.add('pageDown1');
                        sessionStorage.setItem('htmlClass', 'pageDown1');
                    } else if (["iPhone12", "iPhone13", "iPhone13Pro", "iPhone13ProMax", "iPhone14"].indexOf(deviceType) !== -1 || window.innerHeight < 900) { // 48px
                        document.querySelector("html").classList.add('pageDown2');
                        sessionStorage.setItem('htmlClass', 'pageDown2');
                    } else if (["iPhone14ProMax"].indexOf(deviceType) !== -1 || window.innerHeight >= 900) { // 58px
                        document.querySelector("html").classList.add('pageDown3');
                        sessionStorage.setItem('htmlClass', 'pageDown3');
                    }
                }
            })
        });
        wx.config({
            beta: true, // 调用wx.invoke形式的接口值时，该值必须为true。
            debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
            appId: Setting.appid, // 政务微信的cropID
            timestamp: "1608692903", // 生成签名的时间戳
            nonceStr: "XKIvykvwOuAeIbl", // 生成签名的随机串
            signature: "ad0c077e6b5fbfe0c9e5394703d8262a3bc21fc3", // 签名
            jsApiList: ['ext_DeviceInfo_GetInfo'], // 使用的JS接口列表
        });
    }
</script>

<style lang="less">
    #app {
        width: 100%;
        height: 100%;
        font-family: Avenir, Helvetica, Arial, sans-serif;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        color: #2c3e50;
        font-size: 14px;
        position: relative;
        transform: translate(0, 0);
    }
</style>
